package character;

import character.race.Race;
import utilities.WorldDate;

/**
 * Character base class.
 * @author pcdejager
 */
public abstract class Character {
    /**
     * Constructor.
     * @param charName Name of character
     * @param charRace Race of character
     * @param charGender Gender of character
     * @param birth Birth date of the character
     * @param f Family
     */
    public Character(
            final String charName,
            final Race charRace,
            final Gender charGender,
            final WorldDate birth,
            final Family f) {
        name = charName;
        race = charRace;
        gender = charGender;
        age = new Age(birth);
        family = f;
        socialLinks = new SocialLinks();
    }

    /**
     * Get the name of the character.
     * @return The name
     */
    public final String getName() {
        return name;
    }

    /**
     * Get the race of the character.
     * @return The race
     */
    public final Race getRace() {
        return race;
    }

    /**
     * Get the gender of the character.
     * @return The gender
     */
    public final Gender getGender() {
        return gender;
    }

    /**
     * Get the parents.
     * @return The parents
     */
    public final Family getFamily() {
        return family;
    }

    /**
     * Get the social links.
     * @return The links
     */
    public final SocialLinks getSocialLinks() {
        return socialLinks;
    }

    /**
     * Get the character age.
     * @return The age of the character
     */
    public final Age getAge() {
        return age;
    }

    /**
     * Character became pregnant.
     * @param p The pregnancy information
     */
    public final void getPregnant(final Pregnancy p) {
        if (gender == Gender.FEMALE) {
            pregnancy = p;
        }
    }

    /**
     * Check if character is pregnant.
     * @return Return true if pregnant, else false
     */
    public final boolean isPregnant() {
        return (pregnancy != null);
    }

    /**
     * Check if the character went into labor.
     * @return Return true if in labor, else false.
     */
    public final boolean isInLabor() {
        if (pregnancy == null) {
            return false;
        }
        return pregnancy.isInLabor();
    }

    /**
     * Convert the character information to string.
     * @return The string representation
     */
    public final String toString() {
        String result = name
                + " [G:"
                + gender.toString()
                + " R:"
                + race.getName()
                + "] A="
                + age.years();
        return result;
    }

    /**
     * The name of the character.
     */
    private String name;

    /**
     * The race of the character.
     */
    private Race race;

    /**
     * The gender of the character.
     */
    private Gender gender;

    /**
     * The age of the character in days.
     */
    private Age age = null;

    /**
     * The parents.
     */
    private Family family = null;

    /**
     * The socual links.
     */
    private SocialLinks socialLinks = null;

    /**
     * Pregnancy information.
     */
    private Pregnancy pregnancy = null;
}
